//<![CDATA[
function trim (myString)     
{     
    return myString.replace(/^\s+|\s+$/g, "");   
}

function change_order(type,orderby)
{
	if(orderby=="asc")
	{
		orderby="desc";
	}
	else
	{
		orderby="asc";
	}
	document.getElementById("type_title").value=type;
	document.getElementById("order_by").value=orderby;
	document.mainform.submit();
}

function check_all(totalrows)
{
	var status=false;
	if(document.getElementById("checkAll").checked)
	{
		status=true;
	}
		
	for(var i=1;i<=totalrows;i++)
	{
		document.getElementById("check_"+i).checked=status;
	}
	
	
}

function getempfilterresults()
{
	if(trim(document.getElementById('filterby').value)=="")
	{
		alertify.alert("Please select filterby option.");
		document.getElementById("filterby").focus();
		return false;
	}
	else if(trim(document.getElementById('searchText').value)=="")
	{
		alertify.alert("Please enter search value.");
		document.getElementById("searchText").focus();
		return false;
	}
	else if(trim(document.getElementById('searchText').value)!="")
	{
		document.mainform.submit();
	}
}

function getdata(pid)
{
	document.getElementById("pid").value = pid;
	document.mainform.submit();
}


function performoperation(stmsg,status,recid,fieldid)
{
	alertify.confirm("Are you sure, you want to "+stmsg+"?", function (e) {
		if (e) {
			alertify.success("You've clicked OK");
			document.getElementById(fieldid).value=recid;
			document.getElementById('opt_status').value=status;
			document.mainform.submit();
		} else {
			alertify.error("You've clicked Cancel");
		}
	});
	return false;
	
}

function editrecord(editid,fieldid,pagename)
{
	document.getElementById(fieldid).value=editid;
	document.mainform.action=pagename;
	document.mainform.submit();
}
function toggle_div(divname,imgid)
{
	$('#'+divname).toggle('slow', function() {
    
	});
	var imagearr=document.getElementById(imgid).src;
	imagearr=imagearr.split("images/")
	if(imagearr[1]=="desc.gif")
	{
		document.getElementById(imgid).src=imagearr[0]+"images/asc.gif";
	}
	else
	{
		document.getElementById(imgid).src=imagearr[0]+"images/desc.gif";
	}
}
function isNumberKey(evt)
{
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
	    return false;
	
	 return true;
}

// validation function for profile page
function valideditagent_profile()
{
	
	if(trim(document.getElementById("name").value)=="")
	{
		alertify.alert("Name field required!");
		document.getElementById("name").focus();
		return false;
	}
	else if(trim(document.getElementById("gender").value)=="")
	{
		alertify.alert("Gender field required!");
		document.getElementById("gender").focus();
		return false;
	}
	else if(trim(document.getElementById("dob").value)=="")
	{
		alertify.alert("Date of birth field required!");
		document.getElementById("dob").focus();
		return false;
	}
	else if(trim(document.getElementById("email_id").value)=="")
	{
		alertify.alert("Email field required!");
		document.getElementById("email_id").focus();
		return false;
	}
	else if(trim(document.getElementById("contact_number").value)=="")
	{
		alertify.alert("Contact Number field required!");
		document.getElementById("contact_number").focus();
		return false;
	}
	else if(trim(document.getElementById("address").value)=="")
	{
		alertify.alert("Address field required!");
		document.getElementById("address").focus();
		return false;
	}
	else if(trim(document.getElementById("city").value)=="")
	{
		alertify.alert("City field required!");
		document.getElementById("city").focus();
		return false;
	}
	else if(trim(document.getElementById("state").value)=="")
	{
		alertify.alert("State field required!");
		document.getElementById("state").focus();
		return false;
	}
    else if(trim(document.getElementById("country").value)=="")
	{
		alertify.alert("Country field required!");
		document.getElementById("country").focus();
		return false;
	}
    else if(trim(document.getElementById("pincode").value)=="")
	{
		alertify.alert("Pin Code field required!");
		document.getElementById("pincode").focus();
		return false;
	}
}

function valid_pwd()
{
	if(document.getElementById("new_pass").value=="")
	{
		alertify.alert("Please enter new password");
		document.getElementById("new_pass").focus();
		return false;
	}
	else if(document.getElementById("new_pass").value.length<6)
	{
		alertify.alert("Password should be at least 6 characters long!");
		document.getElementById("new_pass").focus();
		return false;
	}
	else if(document.getElementById("confirm_pass").value=="")
	{
		alertify.alert("Please enter repeat password");
		document.getElementById("confirm_pass").focus();
		return false;
	}
	else if(document.getElementById("new_pass").value!=document.getElementById("confirm_pass").value)
	{
		alertify.alert("Seems like you have entered wrong password in repeat password field!");
		document.getElementById("confirm_pass").focus();
		return false;
	}
}
//]]>